package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.car.controller.CarCreationResultController;
import com.tianqu.tms.www.car.viewhelper.CarCreationInputViewHelper;


/**
 * @author zhangxueliang
 * 车辆信息录入Action
 */
public class CarCreationResultAction extends TmsAction{
	private Logger logger = Logger.getLogger(CarCreationResultAction.class);
	private static final String OFF = "off";
	private static final String BACKFLAG = "backFlag"; 
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		//System.out.println(request.getParameter("org.apache.struts.taglib.html.TOKEN"));
		logger.debug(this.getClass().getName() + "#execute was called.");
		

		isToken(mapping, request);
		CarCreationResultController controller = new CarCreationResultController();
		String sysPath = request.getSession().getServletContext().getRealPath("/").replace("/tmsweb", "");
		uc.setAttribute("sysPath", sysPath);
		controller.execute(uc);
		//uc.setAttribute(BACKFLAG, 1);
		CarCreationInputViewHelper viewhelp = (CarCreationInputViewHelper)uc.getAttribute(TmsConstants.VIEWHELP);	
		if(viewhelp.getInsertFlag() == 2){
			//打出提示信息   该车辆数据库已存在！
			setErrorsToRequest(request, TmsConstants.IA002 ,null);
			request.setAttribute(TmsConstants.VIEWHELP, viewhelp);
			return mapping.getInputForward();		
		}
		uc.setAttribute(BACKFLAG, 1);
		
		logger.debug(this.getClass().getName() + "#execute was completed.");
		
		return mapping.findForward(TmsConstants.SUCCESS);
	}
	


}
